Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Go templates in metadata.terraform_workspace section #823

Merged
merged 5 commits into from
Dec 6, 2024

Conversation

aknysh
Copy link
Member

@aknysh aknysh commented Dec 6, 2024

what

  • Enable Go templates in metadata.terraform_workspace and metadata.terraform_workspace_template sections

why

  • Allow using Go templates to dynamically construct Terraform workspaces for Atmos components
components:
  terraform:
    test:
      metadata:
        # Point to the Terraform component
        component: "test"
        # Override Terraform workspace using `Go` templates
        terraform_workspace: '{{ .vars.tenant }}-{{ .vars.environment }}-{{ .vars.stage }}-test'

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced support for Go templates in Atmos stack manifests, including a new metadata section.
    • Improved Atlantis integration with detailed configuration methods and examples.
  • Bug Fixes

    • Updated Atmos tool version to ensure access to the latest features and improvements.
  • Documentation

    • Expanded documentation on Go template processing phases and performance considerations.
    • Clarified workflows and configuration options for Atlantis integration.
  • Chores

    • Updated dependency versions for improved performance and stability.

@aknysh aknysh added the minor New features that do not break anything label Dec 6, 2024
@aknysh aknysh requested a review from osterman December 6, 2024 02:17
@aknysh aknysh self-assigned this Dec 6, 2024
@aknysh aknysh requested review from a team as code owners December 6, 2024 02:17
@aknysh aknysh requested review from hans-d and joe-niland December 6, 2024 02:17
@aknysh aknysh temporarily deployed to preview December 6, 2024 02:17 — with GitHub Actions Inactive
Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

📝 Walkthrough

Walkthrough

The pull request includes several updates across various files. The Dockerfile has been updated to change the Atmos tool version from 1.111.0 to 1.118.0. A new variable for terraform_workspace has been added to the defaults.yaml file. The go.mod file reflects updated dependency versions for golang.org/x/term and golang.org/x/sys. Modifications to the ExecuteTerraform function enhance command handling, while the ProcessStacks function now includes workspace management. Documentation updates clarify Go template usage and improve the Atlantis integration details.

Changes

File Change Summary
examples/quick-start-advanced/Dockerfile Updated ATMOS_VERSION from 1.111.0 to 1.118.0.
examples/tests/stacks/catalog/terraform/template-functions-test2/defaults.yaml Added variable terraform_workspace for dynamic assignment based on tenant, environment, and stage.
go.mod Updated dependency versions: golang.org/x/term from v0.26.0 to v0.27.0, golang.org/x/sys from v0.27.0 to v0.28.0.
internal/exec/terraform.go Enhanced ExecuteTerraform function with new logic for handling varfile, write varfile, and refined clean subcommand. Added debug logging and modified terraform init and deploy command handling.
internal/exec/utils.go Added logic in ProcessStacks to assign TerraformWorkspace from ComponentSection.
website/docs/core-concepts/stacks/templates/templates.mdx Introduced a new metadata section for Go templates, clarified processing phases, and updated best practices.
website/docs/integrations/atlantis.mdx Expanded Atlantis integration documentation, clarified configuration methods, and updated GitHub Actions example.

Possibly related PRs

Suggested reviewers

  • osterman
  • nitrocode

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
internal/exec/utils.go (1)

566-569: LGTM! Consider adding error handling for workspace validation.

The workspace override implementation looks good and aligns with the PR objectives. However, consider adding validation to ensure the workspace name follows Terraform's naming conventions.

 if i, ok := configAndStacksInfo.ComponentSection[cfg.WorkspaceSectionName].(string); ok {
+    if !isValidWorkspaceName(i) {
+        return configAndStacksInfo, fmt.Errorf("invalid workspace name: %s", i)
+    }
     configAndStacksInfo.TerraformWorkspace = i
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 822ab17 and f5e894e.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (7)
  • examples/quick-start-advanced/Dockerfile (1 hunks)
  • examples/tests/stacks/catalog/terraform/template-functions-test2/defaults.yaml (1 hunks)
  • go.mod (2 hunks)
  • internal/exec/terraform.go (1 hunks)
  • internal/exec/utils.go (1 hunks)
  • website/docs/core-concepts/stacks/templates/templates.mdx (1 hunks)
  • website/docs/integrations/atlantis.mdx (1 hunks)
🧰 Additional context used
📓 Learnings (1)
examples/quick-start-advanced/Dockerfile (2)
Learnt from: aknysh
PR: cloudposse/atmos#775
File: examples/quick-start-advanced/Dockerfile:9-9
Timestamp: 2024-11-12T05:52:05.088Z
Learning: It is acceptable to set `ARG ATMOS_VERSION` to a future version like `1.105.0` in `examples/quick-start-advanced/Dockerfile` if that will be the next release.
Learnt from: osterman
PR: cloudposse/atmos#801
File: examples/quick-start-advanced/Dockerfile:9-9
Timestamp: 2024-11-23T00:13:22.004Z
Learning: When updating the `ATMOS_VERSION` in Dockerfiles, the team prefers to pin to the next future version when the PR merges, even if the version is not yet released.
🔇 Additional comments (6)
internal/exec/terraform.go (1)

124-127: Variable assignments are correctly implemented

The variables varFile and planFile are appropriately assigned using helper functions.

examples/quick-start-advanced/Dockerfile (1)

9-9: ATMOS_VERSION updated in line with team practices

Updating ATMOS_VERSION to the future release 1.118.0 aligns with team preferences noted in previous learnings.

examples/tests/stacks/catalog/terraform/template-functions-test2/defaults.yaml (1)

9-9: Dynamic terraform_workspace variable is correctly defined

The use of Go templates for terraform_workspace enhances configurability.

go.mod (1)

46-46: Dependencies updated to latest versions

Updating golang.org/x/term and golang.org/x/sys ensures the module uses the latest improvements.

Also applies to: 250-250

website/docs/core-concepts/stacks/templates/templates.mdx (1)

247-247: Documentation accurately reflects new metadata support

Adding metadata to the list of sections supporting Go templates is appropriate.

website/docs/integrations/atlantis.mdx (1)

676-676: LGTM! Version update is consistent.

The Atmos version update to 1.118.0 aligns with the codebase changes.

@aknysh aknysh merged commit 9e0ff68 into main Dec 6, 2024
30 of 31 checks passed
@aknysh aknysh deleted the fix-metadata-templates branch December 6, 2024 13:36
Copy link

github-actions bot commented Dec 6, 2024

These changes were released in v1.118.0.

Cerebrovinny pushed a commit that referenced this pull request Dec 7, 2024
* updates

* updates

* updates

* updates
@coderabbitai coderabbitai bot mentioned this pull request Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor New features that do not break anything
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants